#! /bin/sh

get_k8sgpt() {
    k8sgpt_version=$(curl -s https://api.github.com/repos/k8sgpt-ai/k8sgpt/tags | jq -r '.[0].name')
    echo "k8sgpt_version: ${k8sgpt_version}"
    cli="k8sgpt"
    bin_path="/usr/local/bin"
    file_name="k8sgpt_Linux_x86_64"
    sudo rm -rf ${bin_path}/${cli}

    wget https://github.com/k8sgpt-ai/k8sgpt/releases/download/${k8sgpt_version}/${file_name}.tar.gz

    # wget https://521github.com/extdomains/github.com/k8sgpt-ai/k8sgpt/releases/download/${k8sgpt_version}/${file_name}.tar.gz
    # wget https://ghproxy.net/https://github.com/k8sgpt-io/k8sgpt/releases/download/${k8sgpt_version}/${file_name}.tar.gz
    tar -xzvf ${file_name}.tar.gz
    mv ${file_name} ${cli}
    chmod +x ${cli}
    sudo mv ${cli} ${bin_path}
    rm -rf LICENSE CHANGELOG.md README.md ${file_name}.tar.gz
}
get_k8sgpt
